package com.iamteer.learnactivity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    private Button btnStartBActivity;
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        System.out.println("onCreate");
        setContentView(R.layout.activity_main);

        btnStartBActivity = (Button) findViewById(R.id.btnStartActivityB);

        btnStartBActivity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, ActivityB.class); //实例化一个Intent
//                intent.putExtra("data", "Data from Main Activity");      //添加要传递的数据，这里的数据可以是字符串、整形、字符数组等等

                Bundle bundle = new Bundle();       //实例化一个Bundle
                bundle.putString("name", "Chuck");  //写入数据，同样可以是字符串，整形、字符数组等
                bundle.putInt("age", 27);           //写入数据，同样可以是字符串，整形、字符数组等
                intent.putExtras(bundle);           //传递数据

                startActivity(intent);  //启动刚才定义的另外一个Activity
            }
        });

    }
    @Override
    protected void onStart() {
        super.onStart();

        System.out.println("onStart");
    }

    @Override
    protected void onResume() {
        super.onResume();

        System.out.println("onResume");
    }

    @Override
    protected void onPause() {
        super.onPause();

        System.out.println("onPause");
    }

    @Override
    protected void onStop() {
        super.onStop();

        System.out.println("onStop");
    }

    @Override
    protected void onRestart() {
        super.onRestart();

        System.out.println("onRestart");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        System.out.println("onDestroy");
    }
}
